home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 4490 / 4490.xpi / chrome / wmn.jar / content / notifications.js < prev    next >
Text File  |  2009-12-23  |  3KB  |  85 lines

  1. //@line 36 "/cygdrive/c/builds/tinderbox/Tb-Mozilla1.8.0-Release/WINNT_5.2_Depend/mozilla/mail/components/preferences/notifications.js"
  2.  
  3. var gNotificationsDialog = {
  4.   mSound: null,
  5.  
  6.   init: function()
  7.   {
  8.   },
  9.  
  10.   convertURLToLocalFile: function(aFileURL)
  11.   {
  12.     // convert the file url into a nsILocalFile
  13.     if (aFileURL)
  14.     {
  15.       var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  16.       var fph = ios.getProtocolHandler("file").QueryInterface(Components.interfaces.nsIFileProtocolHandler);
  17.       return fph.getFileFromURLSpec(aFileURL);
  18.     }
  19.     else
  20.       return null;
  21.   },
  22.  
  23.   readSoundLocation: function()
  24.   {
  25.     var soundUrlLocation = document.getElementById('soundUrlLocation');
  26.     soundUrlLocation.value = document.getElementById("pref-soundUrl").value;
  27.     var f=this.convertURLToLocalFile(soundUrlLocation.value)
  28.     if(f!=null){
  29.       soundUrlLocation.label = f.leafName;    
  30.       soundUrlLocation.image = "moz-icon://" + soundUrlLocation.label + "?size=16";
  31.     }
  32.     return undefined;
  33.   },
  34.  
  35.   previewSound: function ()
  36.   {
  37.     if (!this.mSound)
  38.       this.mSound = Components.classes["@mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);
  39.  
  40.     var soundLocation;
  41.     soundLocation = document.getElementById("newMailNotificationType").value == "true"?
  42.                     document.getElementById("soundUrlLocation").value : "_moz_mailbeep"
  43.  
  44.     if (soundLocation.indexOf("file://") == -1){
  45.       var os = Components.classes["@mozilla.org/xre/app-info;1"]
  46.                   .getService(Components.interfaces.nsIXULRuntime).OS;
  47.       if(os=="Darwin")soundLocation="";
  48.     
  49.       this.mSound.playSystemSound(soundLocation);
  50.     }else{
  51.       var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  52.       this.mSound.play(ioService.newURI(soundLocation, null, null));
  53.     }
  54.   },
  55.  
  56.   browseForSoundFile: function ()
  57.   {
  58.     const nsIFilePicker = Components.interfaces.nsIFilePicker;
  59.     var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
  60.  
  61.     // if we already have a sound file, then use the path for that sound file
  62.     // as the initial path in the dialog.
  63.     var localFile = this.convertURLToLocalFile(document.getElementById("soundUrlLocation").value);
  64.     if (localFile)
  65.       fp.displayDirectory = localFile;
  66.  
  67.     // XXX todo, persist the last sound directory and pass it in
  68.     // XXX todo filter by .wav
  69.     fp.init(window, document.getElementById("bundlePreferences").getString("soundFilePickerTitle"), nsIFilePicker.modeOpen);
  70.     fp.appendFilters(nsIFilePicker.filterAll);
  71.  
  72.     var ret = fp.show();
  73.     if (ret == nsIFilePicker.returnOK)
  74.     {
  75.       var mailnewsSoundFileUrl = document.getElementById("soundUrlLocation");
  76.  
  77.       // convert the nsILocalFile into a nsIFile url
  78.       // mailnewsSoundFileUrl.value = fp.fileURL.spec;
  79.       document.getElementById("pref-soundUrl").value = fp.fileURL.spec;
  80.       this.readSoundLocation(); // XXX We shouldn't have to be doing this by hand
  81.     }
  82.   },
  83. };
  84.  
  85.